package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.View;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.activity.AddPlanActivity;
import com.wnhz.work.yz.base.BaseRVAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.bean.PlanFragmentBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/3/10.
 */
public class PlanFragmentAdapter extends BaseRVAdapter {
    private List<PlanFragmentBean.InfoEntity> info = new ArrayList<>();

    /**
     * 构造器
     *
     * @param context 上下文
     * @param list    数据集合
     */
    public PlanFragmentAdapter(Context context, @NonNull List list) {
        super(context, list);
        info = list;
    }
    private boolean flag=false;

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_plan_fragment;
    }

    @Override
    public void onBind(BaseViewHolder holder, final int position) {
        holder.setTextView(R.id.name, info.get(position).getTitle());
        switch (Integer.parseInt(info.get(position).getType())) {
            case 0:
                holder.setTextView(R.id.product_type, "周计划");
                break;
            case 1:
                holder.setTextView(R.id.product_type, "月计划");
                break;
            case 2:
                holder.setTextView(R.id.product_type, "自定义");
                break;
        }
        holder.setTextView(R.id.address, info.get(position).getStart_time() + "——" + info.get(position).getEnd_time());
        holder.setTextView(R.id.time, info.get(position).getCreate_at());
        //  0进行中 1已完成 2终止 3未完成 4待点评
        switch (Integer.parseInt(info.get(position).getStatus())) {
            case 0:
                holder.setTextView(R.id.progress, "进行中");
                break;
            case 1:
                holder.setTextView(R.id.progress, "未完成");
                break;
            case 2:
                holder.setTextView(R.id.progress, "已完成");
                break;
            case 3:
                holder.setTextView(R.id.progress, "终止");
                break;
            case 4:
                holder.setTextView(R.id.progress, "待点评");
                break;
        }
        holder.getView(R.id.rl_max).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent = new Intent(mContext, AddPlanActivity.class);
                    intent.putExtra("planid", info.get(position).getPlanid());
                    intent.putExtra("status", info.get(position).getStatus());
                    mContext.startActivity(intent);
            }
        });

    }

}
